home *** CD-ROM | disk | FTP | other *** search
- /* fprintf.c from p. 423 of Turbo C Bible */
- #include <stdio.h>
- char str[] = "Testing fprintf...";
- char c = '\n';
- int i = 100;
- double x = 1.23456;
- main()
- {
- FILE *outfile;
- char filename[81];
- printf("Enter name of a file to open for WRITING:");
- gets(filename);
- /* Open the file for reading */
- if ((outfile = fopen(filename, "w")) == NULL)
- {
- printf("fopen failed.\n");
- exit(0);
- }
- /* Write to this file ... */
- fprintf(outfile, "%s writing to file %s%c", str, filename, c);
- fprintf(outfile, "Integer: decimal = %d, \ octal = %o, hex = %X\n",
- i,i,i);
- fprintf(outfile, "Double: %f(in default f format)\n", x);
- fprintf(outfile, " %.2f(in >2f format)\n", x);
- fprintf(outfile, " %g(in default g format)\n", x);
- /* Tell user to type file to see results */
- fprintf(stdout, "Use the command 'TYPE %s' to see results\n", filename);
- }